package com.example.serialization.serializable.transfer.gson;
// JavaServer.java
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class JavaServer {
    public static void main(String[] args) {
        final int PORT = 9090;

        try (ServerSocket serverSocket = new ServerSocket(PORT)) {
            System.out.println("Java 服务端启动，等待连接...");
            Socket clientSocket = serverSocket.accept();
            System.out.println("客户端已连接: " + clientSocket.getInetAddress());

            // 接收客户端消息
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(clientSocket.getInputStream())
            );
            String message = reader.readLine();
            System.out.println("[Java 服务端接收] " + message);

            // 发送响应
            PrintWriter writer = new PrintWriter(clientSocket.getOutputStream(), true);
            writer.println("你好，Python 客户端！我是 Java 服务端。");

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}